from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-30 14:04:11.401493
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 30, Dec, 2021
Time: 14:04:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6563
Nobs: 521.000 HQIC: -48.1035
Log likelihood: 6042.58 FPE: 9.63512e-22
AIC: -48.3915 Det(Omega_mle): 8.11981e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358778 0.077256 4.644 0.000
L1.Burgenland 0.099055 0.043396 2.283 0.022
L1.Kärnten -0.115013 0.022377 -5.140 0.000
L1.Niederösterreich 0.183138 0.090017 2.034 0.042
L1.Oberösterreich 0.106133 0.089739 1.183 0.237
L1.Salzburg 0.283943 0.046743 6.075 0.000
L1.Steiermark 0.022046 0.060279 0.366 0.715
L1.Tirol 0.111337 0.048648 2.289 0.022
L1.Vorarlberg -0.080434 0.042912 -1.874 0.061
L1.Wien 0.037154 0.081385 0.457 0.648
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.020862 0.170251 0.123 0.902
L1.Burgenland -0.047696 0.095634 -0.499 0.618
L1.Kärnten 0.035932 0.049313 0.729 0.466
L1.Niederösterreich -0.208428 0.198373 -1.051 0.293
L1.Oberösterreich 0.455548 0.197761 2.304 0.021
L1.Salzburg 0.313268 0.103009 3.041 0.002
L1.Steiermark 0.108590 0.132839 0.817 0.414
L1.Tirol 0.314934 0.107206 2.938 0.003
L1.Vorarlberg 0.012889 0.094567 0.136 0.892
L1.Wien 0.004003 0.179350 0.022 0.982
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.217797 0.039373 5.532 0.000
L1.Burgenland 0.092590 0.022117 4.186 0.000
L1.Kärnten -0.005246 0.011404 -0.460 0.646
L1.Niederösterreich 0.228112 0.045876 4.972 0.000
L1.Oberösterreich 0.159985 0.045735 3.498 0.000
L1.Salzburg 0.038271 0.023822 1.607 0.108
L1.Steiermark 0.029854 0.030721 0.972 0.331
L1.Tirol 0.078857 0.024793 3.181 0.001
L1.Vorarlberg 0.055706 0.021870 2.547 0.011
L1.Wien 0.105200 0.041477 2.536 0.011
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.153592 0.039338 3.904 0.000
L1.Burgenland 0.039683 0.022097 1.796 0.073
L1.Kärnten -0.012641 0.011394 -1.109 0.267
L1.Niederösterreich 0.162577 0.045836 3.547 0.000
L1.Oberösterreich 0.334523 0.045695 7.321 0.000
L1.Salzburg 0.101423 0.023801 4.261 0.000
L1.Steiermark 0.111760 0.030694 3.641 0.000
L1.Tirol 0.090046 0.024771 3.635 0.000
L1.Vorarlberg 0.054747 0.021851 2.505 0.012
L1.Wien -0.036663 0.041441 -0.885 0.376
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.149777 0.073650 2.034 0.042
L1.Burgenland -0.036971 0.041371 -0.894 0.372
L1.Kärnten -0.036782 0.021333 -1.724 0.085
L1.Niederösterreich 0.132841 0.085815 1.548 0.122
L1.Oberösterreich 0.169903 0.085550 1.986 0.047
L1.Salzburg 0.258542 0.044561 5.802 0.000
L1.Steiermark 0.080974 0.057466 1.409 0.159
L1.Tirol 0.135266 0.046377 2.917 0.004
L1.Vorarlberg 0.103117 0.040909 2.521 0.012
L1.Wien 0.046289 0.077586 0.597 0.551
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080469 0.058277 1.381 0.167
L1.Burgenland 0.017739 0.032735 0.542 0.588
L1.Kärnten 0.051250 0.016880 3.036 0.002
L1.Niederösterreich 0.182793 0.067903 2.692 0.007
L1.Oberösterreich 0.326472 0.067693 4.823 0.000
L1.Salzburg 0.050827 0.035260 1.441 0.149
L1.Steiermark -0.003232 0.045471 -0.071 0.943
L1.Tirol 0.126773 0.036696 3.455 0.001
L1.Vorarlberg 0.060505 0.032370 1.869 0.062
L1.Wien 0.107693 0.061391 1.754 0.079
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174861 0.070622 2.476 0.013
L1.Burgenland 0.010907 0.039670 0.275 0.783
L1.Kärnten -0.061243 0.020456 -2.994 0.003
L1.Niederösterreich -0.110955 0.082287 -1.348 0.178
L1.Oberösterreich 0.222296 0.082033 2.710 0.007
L1.Salzburg 0.040697 0.042729 0.952 0.341
L1.Steiermark 0.261647 0.055103 4.748 0.000
L1.Tirol 0.489719 0.044470 11.012 0.000
L1.Vorarlberg 0.068860 0.039227 1.755 0.079
L1.Wien -0.093394 0.074396 -1.255 0.209
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.140836 0.078275 1.799 0.072
L1.Burgenland -0.010145 0.043969 -0.231 0.818
L1.Kärnten 0.063440 0.022672 2.798 0.005
L1.Niederösterreich 0.174233 0.091204 1.910 0.056
L1.Oberösterreich -0.071513 0.090923 -0.787 0.432
L1.Salzburg 0.221467 0.047360 4.676 0.000
L1.Steiermark 0.139397 0.061075 2.282 0.022
L1.Tirol 0.052756 0.049289 1.070 0.284
L1.Vorarlberg 0.143278 0.043478 3.295 0.001
L1.Wien 0.149137 0.082458 1.809 0.071
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.463072 0.044242 10.467 0.000
L1.Burgenland -0.001878 0.024852 -0.076 0.940
L1.Kärnten -0.014857 0.012815 -1.159 0.246
L1.Niederösterreich 0.183910 0.051550 3.568 0.000
L1.Oberösterreich 0.230373 0.051391 4.483 0.000
L1.Salzburg 0.024170 0.026768 0.903 0.367
L1.Steiermark -0.009039 0.034520 -0.262 0.793
L1.Tirol 0.077675 0.027859 2.788 0.005
L1.Vorarlberg 0.053015 0.024575 2.157 0.031
L1.Wien -0.003925 0.046607 -0.084 0.933
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.028924 0.091187 0.159023 0.145320 0.071017 0.080112 0.011736 0.212578
Kärnten 0.028924 1.000000 -0.030485 0.132869 0.051233 0.076563 0.453982 -0.077053 0.097615
Niederösterreich 0.091187 -0.030485 1.000000 0.293299 0.107553 0.257192 0.050036 0.146435 0.255994
Oberösterreich 0.159023 0.132869 0.293299 1.000000 0.201020 0.287276 0.156336 0.128828 0.203981
Salzburg 0.145320 0.051233 0.107553 0.201020 1.000000 0.123908 0.060843 0.109453 0.078823
Steiermark 0.071017 0.076563 0.257192 0.287276 0.123908 1.000000 0.131437 0.091699 0.011696
Tirol 0.080112 0.453982 0.050036 0.156336 0.060843 0.131437 1.000000 0.060613 0.130744
Vorarlberg 0.011736 -0.077053 0.146435 0.128828 0.109453 0.091699 0.060613 1.000000 -0.017173
Wien 0.212578 0.097615 0.255994 0.203981 0.078823 0.011696 0.130744 -0.017173 1.000000